package net.ys.controller;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import net.ys.bean.Person;
import net.ys.service.TestService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author: NMY
 * @Date: 2020/10/14
 * @Time: 19:28
 */

@Data
@Slf4j
@RestController
public class TestController {

    @Resource
    private TestService testService;

    @GetMapping("/test")
    public String test() {
        String demo = "test:" + System.currentTimeMillis() + " this is a gray version!";
        return demo;
    }

    @GetMapping("/person")
    public Person person() {
        Person person = new Person();
        person.setName("tom");
        person.setId(1);
        return person;
    }

    @GetMapping("/sleep")
    public String sleep(int time) {
        try {
            Thread.sleep(time * 1000);
        } catch (Exception e) {
            log.error(e.getMessage());
        }
        return "sleep:" + System.currentTimeMillis() + " this is a gray version!";
    }

    @GetMapping("/err")
    public void err() {
        try {
            testService.demo();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
